package cn.njupt.cmpSort;
//插入排序优化,先找到待插入的索引，最后插入进去，相比于InsertSection1减少了交换次数
public class InsertionSort2<E extends Comparable<E>> extends Sort<E>{
    @Override
    public void sort() {

        for (int begin = 1; begin <array.length; begin++) {
            int cur=begin;
            E initalValue=array[cur];
            while(cur>0 &&cmpElements(array[cur-1],initalValue)>0){
                array[cur]=array[cur-1];
                cur--;
            }
            array[cur]=initalValue;
        }

    }
}
